package ch.service.impl;

import ch.dao.fdao;
import ch.entity.danger;
import ch.service.fservice;
import cn.hutool.json.JSONUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service
public class fserviceimpl implements fservice {
    @Autowired
    private fdao fdao;
    @Override
    public List getfilename(String name) {
        String getfilename = fdao.getfilename(name);
        System.out.println(getfilename);
        System.out.println(name);
        List list=null;
        if (getfilename==null){
            list=new ArrayList();
        }
        else {
            list=JSONUtil.toList(getfilename,List.class);
        }
        System.out.println(list);
        return list;
    }

    @Override
    public boolean getfile(String name) {
        boolean f=false;
        if (fdao.getfile(name)!=null){
            f=true;
        }
        return f;
    }

    @Override
    public boolean setfilename(String name,String filename) {
        List getfilename = this.getfilename(name);
        getfilename.add(filename);
        String s = JSONUtil.toJsonStr(getfilename);
        danger danger=new danger();
        System.out.println(s);
        danger.setName(name);
        danger.setFilename(s);
        boolean setfilename = fdao.setfilename(danger);

        return setfilename;
    }
}
